from flask_sqlalchemy import SQLAlchemy

from datetime import datetime

db = SQLAlchemy()

def init_db(app):
    db.init_app(app)

# class User(db.Model):
#     id = db.Column(db.Integer,primary_key=True)
#     username = db.Column(db.String(10))
#     password = db.Column(db.String(20))
#     email = db.Column(db.String(30))
#     # age = db.Column(db.Integer)
#     update_at = db.Column(db.DateTime,default=datetime.now)

#     def __init__(self,username,password,email):
#         self.username = username
#         self.password = password
#         self.email = email

#     def __repr__(self):
#         return '<User %s>' % self.username

class UserInfo(db.Model):
    UserID = db.Column(db.Integer,primary_key=True)
    UserName = db.Column(db.String(50))
    Password = db.Column(db.String(50))
    Role = db.Column(db.String(50))
    # email = db.Column(db.String(30))
    # age = db.Column(db.Integer)
    # update_at = db.Column(db.DateTime,default=datetime.now)

    def __init__(self,UserName,Password,Role):
        self.UserName = UserName
        self.Password = Password
        self.Role = Role

    # def __repr__(self):
    #     return 'userID={},username={},password={},role={}'.format(
    #         self.UserID,self.UserName,self.Password,self.Role
    #     )

    def set_userid(self,UserID):
        self.UserID = UserID

    def to_json(self):
        return {
            'userID':self.UserID,
            'username':self.UserName,
            'password':self.Password,
            'role':self.Role
        }
    
class StudInfo(db.Model):
    StudNo = db.Column(db.Integer,primary_key=True)
    StudName = db.Column(db.String(50))
    StudSex = db.Column(db.String(2))
    Email = db.Column(db.String(50))
    # email = db.Column(db.String(30))
    # age = db.Column(db.Integer)
    # update_at = db.Column(db.DateTime,default=datetime.now)

    def __init__(self,StudName,StudSex,Email):
        self.StudName = StudName
        self.StudSex = StudSex
        self.Email = Email

    def set_studno(self,StudNo):
        self.StudNo = StudNo

    def to_json(self):
        return {
            'StudNo':self.StudNo,
            'StudName':self.StudName,
            'StudSex':self.StudSex,
            'Email':self.Email
        }